package com.fingerth.demo.utils

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.View
import com.bumptech.glide.request.RequestOptions

fun View.OnClickListener.setClick(vararg v:View) = v.forEach { it.setOnClickListener(this) }

inline fun <reified T : Activity> ktStartActivity(context: Context?) {
    val intent = Intent(context, T::class.java)
    context?.startActivity(intent)
}

inline fun <reified T : Activity> ktStartActivity(context: Context?, block: Intent.() -> Unit) {
    val intent = Intent(context, T::class.java)
    intent.block()
    context?.startActivity(intent)
}

fun RequestOptions.place(): RequestOptions = ColorDrawable(Color.rgb(200 + (0..30).random(), 220 + (0..30).random(), 230 + (0..30).random())).run { placeholder(this).error(this) }
fun dp2px(context: Context?, dpValue: Float): Int = context?.let { (dpValue * it.resources.displayMetrics.density + 0.5f).toInt() } ?: 0